package com.tmt.api.web;

import java.util.concurrent.CompletableFuture;

import com.swak.annotation.Auth;
import com.swak.entity.Result;
import com.swak.vertx.annotation.GetMapping;
import com.swak.vertx.annotation.RestController;
import com.swak.vertx.annotation.VertxReferer;
import com.swak.vertx.transport.Subject;
import com.tmt.api.service.UserServiceAsync;

/**
 * 需要Admin访问权限的 API
 * 
 * @author lifeng
 */
@RestController(path = "/api/admin", value = "adminApi")
public class AdminApi {

	@VertxReferer
	private UserServiceAsync userService;

	/**
	 * 获取用户
	 * 
	 * @param subject
	 * @return
	 */
	@GetMapping("/get")
	public CompletableFuture<Result> get(Subject subject) {
		return userService.get(subject.getPrincipal().getIdAsLong()).thenApply(res -> Result.success(res));
	}

	/**
	 * 获取用户
	 * 
	 * @param subject
	 * @return
	 */
	@Auth(roles = { "admin:role1", "admin:role2" })
	@GetMapping("/get_role")
	public CompletableFuture<Result> get_role(Subject subject) {
		return userService.get(subject.getPrincipal().getIdAsLong()).thenApply(res -> Result.success(res));
	}

	/**
	 * 获取用户
	 * 
	 * @param subject
	 * @return
	 */
	@Auth(permissions = { "admin:role1:op1", "admin:role2:op2" })
	@GetMapping("/get_permission")
	public CompletableFuture<Result> get_permission(Subject subject) {
		return userService.get(subject.getPrincipal().getIdAsLong()).thenApply(res -> Result.success(res));
	}
}
